package com.tech.repo;

import com.tech.model.GlobalConfigEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Component;

/**
 * Created by zouyao on 2023/06/06
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class CommonRepo {
    private final     TemplateEntityRepository     templateRepo;
    private final     GlobalConfigEntityRepository configRepo;

    public String getConfigByKey(String key){

        GlobalConfigEntity config = new GlobalConfigEntity();
        config.setKey(key);
        config.setStatus(true);

        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
                .withMatcher("key", ExampleMatcher.GenericPropertyMatchers.contains());
        GlobalConfigEntity globalConfigEntity = configRepo.findOne(Example.of(config, exampleMatcher)).get();

        return globalConfigEntity.getVal();
    }
}
